\defmodule {HalfNormalGen}

This class implements methods for generating random variates from the 
{\em half-normal\/} distribution with parameters $\mu$ and $\sigma > 0$.
Its density is
\begin{htmlonly}
\eq
   f(x) = (\sqrt{2/\pi}/\sigma) e^{-(x-\mu)^2/(2\sigma^2)},
   \qquad \mbox {for  } x >= \mu,
\endeq
\end{htmlonly}
\begin{latexonly} 
\begin{eqnarray*} 
 f(x) &=& \frac{1}{\sigma}\sqrt{\frac2\pi}\; e^{-(x-\mu)^2/2\sigma^2},
   \qquad \mbox {for  } x \ge \mu. \\[6pt]
f(x) &=& 0, \qquad \mbox {for  } x < \mu.
\end{eqnarray*} 
\end{latexonly}

\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        HalfNormalGen
 * Description:  generator of random variates from the half-normal distribution
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.randvar;\begin{hide}
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;
\end{hide}

public class HalfNormalGen extends RandomVariateGen \begin{hide} {
    
   // Distribution parameters
   protected double mu;
   protected double sigma;
\end{hide}
\end{code}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Constructors}
\begin{code}

   public HalfNormalGen (RandomStream s, double mu, double sigma) \begin{hide} {
      super (s, new HalfNormalDist (mu, sigma));
      setParams (mu, sigma);
   }\end{hide}
\end{code}
  \begin{tabb}  Creates a new {\em half-normal} generator with parameters $\mu =$ 
     \texttt{mu} and $\sigma =$ \texttt{sigma}, using stream \texttt{s}.
\end{tabb}
\begin{code}

   public HalfNormalGen (RandomStream s, HalfNormalDist dist) \begin{hide} {
      super (s, dist);
      if (dist != null)
         setParams (dist.getMu(), dist.getSigma());
   }\end{hide}
\end{code}
\begin{tabb} Creates a new generator for the distribution \texttt{dist},
     using stream \texttt{s}.
\end{tabb}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Methods}
\begin{code}

   public static double nextDouble (RandomStream s, double mu, double sigma)\begin{hide} {
      return HalfNormalDist.inverseF (mu, sigma, s.nextDouble());
   }\end{hide}
\end{code}
\begin{tabb} Generates a variate from the {\em half-normal\/} distribution with
 parameters $\mu = $~\texttt{mu} and $\sigma = $~\texttt{sigma}, 
using stream \texttt{s}.
\end{tabb}
\begin{htmlonly}
   \param{s}{the random stream}
   \param{mu}{the parameter mu}
   \param{sigma}{the parameter sigma}
   \return{Generates a variate from the {\em HalfNormal\/} distribution}
\end{htmlonly}
\begin{code}

   public double getMu()\begin{hide} {
      return mu;
   }\end{hide}
\end{code}
  \begin{tabb} Returns the parameter $\mu$ of this object.
  \end{tabb}
\begin{htmlonly}
   \return{the parameter mu}
\end{htmlonly}
\begin{code}

   public double getSigma()\begin{hide} {
      return sigma;
   }\end{hide}
\end{code}
  \begin{tabb} Returns the parameter $\sigma$ of this object.
  \end{tabb}
\begin{htmlonly}
   \return{the parameter mu}
\end{htmlonly}
\begin{code}\begin{hide}

   protected void setParams (double mu, double sigma) {
      if (sigma <= 0.0)
         throw new IllegalArgumentException ("sigma <= 0");
      this.mu = mu;
      this.sigma = sigma;
   }
}\end{hide}
\end{code}
